<?php
namespace app\index\controller;
use app\index\controller\Base;
use think\Db;

// 搜索页
class Search extends Base
{
    public function index()
    {
        $keywords = input('keywords');
        if($keywords){
            $map['title'] = ['like','%'.$keywords.'%'];
            $search = db('article')
                ->where($map)
                ->order('id desc')
                ->paginate($listRows = 3, $simple = false, $config = ['query'=>array('keywords'=>$keywords)]);
            
            $this->assign('search',$search);
            $this->assign('keywords',$keywords);
        }else{

            $this->assign('search',null);
            $this->assign('keywords','暂无数据');
        }

        return $this->fetch();
    }
}
